<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$return['status']=$this->fuwuorder_status;
$return['order_types']=$this->order_types;
if($_RQ['op']=='edit'){
	if($_RQ['postdata']){
		$post=get_postdata();
		if(!$post['mobile'] || !$post['address']){
			exi('必须填写客户电话,地址等','error');
		}
		$serve_time=strtotime($post['serve_time']);
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$post['mid'],
			'type'=>$post['type'],
			'worker_id'=>$post['worker_id'],
			'pid'=>$post['pid'],
			'storeid'=>$post['storeid'],
			'total'=>1,
			'address'=>$post['address'],
			'username'=>$post['username'],
			'mobile'=>$post['mobile'],
			'ordersn'=>get_ordersn('jy_shopbaoxiu_order','ordersn'),
			'remark'=>$post['remark'],
			'serve_time'=>$serve_time,
			'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_shopbaoxiu_order',$insert);
		$insert['id']=pdo_insertid();
		$this->model('model')->payresult($insert,$payresult);
		$this->model('notice')->notice_fuwuorder($insert);
		if($insert['worker_id']){
			$insert['shifu_id']=$insert['worker_id'];
			$insert['order_id']=pdo_getcolumn('jy_wxshifu_order',array('orderid'=>$insert['id'],'uniacid'=>$_SESSION['uniacid'],'plugin'=>'jy_shopbaoxiu'),'id');
			if(!$insert['order_id']){
				$insert['sendtype']=1;
				$insert['order_id']=model('jy_wxshifu/model')->addorder($insert,0,'jy_shopbaoxiu');
			}
			model('jy_wxshifu/order')->order_sendget($insert);
		}else{
			model('jy_wxshifu/model')->addorder($insert,0,'jy_shopbaoxiu');
			pdo_update('jy_shopbaoxiu_order',array('status'=>8),array('id'=>$insert['id'],'uniacid'=>$_SESSION['uniacid']));
		}
		exi('生成订单成功！','','/fuwu.order/');
	}
	$return['item']=array('type'=>0);
	$htmls=array(
		'type'=>'edit',
		'desc'=>'创建订单',
		'edit'=>array(
			array('type'=>'choose','title'=>'选择会员','name'=>'mid','action'=>'core/member.get_member/','choose_title'=>'选择会员'),
			array('name'=>'username','title'=>'用户姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'用户电话','type'=>'string'),
			array('type'=>'select2','name'=>'groupid','options'=>'groups','title'=>'维修类目',
				'name2'=>'pid','options2'=>'list','title2'=>'维修项目',
			),	
			array('name'=>'remark','title'=>'简单故障描述','type'=>'text'),
			array('name'=>'type','title'=>'服务类型','type'=>'radio','options'=>'types'),
			array('name'=>'address','title'=>'上门地址','type'=>'string','show'=>array('type'=>0)),
			array('name'=>'serve_time','title'=>'上门时间','type'=>'time','show'=>array('type'=>0)),
			array('type'=>'select','title'=>'指定门店','name'=>'storeid','options'=>'stores'),
			array('type'=>'select','title'=>'指定技术员/师傅','name'=>'worker_id','options'=>'peisongs'),
		)
	);
	$return['groups']=pdo_getall('jy_shopbaoxiu_group',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id','paixu desc,id desc');
	foreach($return['groups'] as &$gv){
		$gv['list']=pdo_getall('jy_shopbaoxiu_list',array('uniacid'=>$_SESSION['uniacid'],'groupid'=>$gv['id']),array('id','title','desc','price','vip_price','order_types'),'id');
	}
	$return['peisongs']=pdo_getall('jy_wxshifu_member',array('uniacid'=>$_SESSION['uniacid'],'type'=>1,'status'=>1),array('id','title'));
	$return['stores']=pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1),array('id','title'));
	$return['types']=array('上门维修','到店维修');
	$return['htmls']=$htmls;
	exi($return);
}
